package com.example.wechat.controller;

import com.example.wechat.mapper.WeChatMapper;
import com.example.wechat.model.WechatMessage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;
import java.util.List;

@RestController
public class MessageSearchController {

	@Autowired
	private WeChatMapper weChatMapper;

	@GetMapping("/api/messages/search")
	public List<WechatMessage> searchMessages(@RequestParam String q, Principal principal) {
		return weChatMapper.findByContentContainingAndFromOrTo(q, principal.getName());
	}
}